<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="include :: header('固定资产信息列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="formId">
                <div class="select-list">
                    <ul>
                        <li>
                            <label>资产编号：</label>
                            <input type="text" name="assetNumber"/>
                        </li>
                        <li>
                            <label>资产名称：</label>
                            <input type="text" name="assetName"/>
                        </li>
                        <li>
                            <label>资产型号：</label>
                            <input type="text" name="assetModel"/>
                        </li>
                        <li>
                            <label>资产位置：</label>
                            <input type="text" name="location"/>
                        </li>
                        <li>
                            <label>供应商：</label>
                            <input type="text" name="supplier"/>
                        </li>
                        <li>
                            <label>工号：</label>
                            <input type="text" name="userId"/>
                        </li>
                        <li>
                            <label>IP：</label>
                            <input type="text" name="ipAddress"/>
                        </li>
                        <li>
                            <label>SN：</label>
                            <input type="text" name="snNumber"/>
                        </li>
                        <li>
                            <label>MAC：</label>
                            <input type="text" name="macAddress"/>
                        </li>
                        <li>
                            <label>OA编号：</label>
                            <input type="text" name="oaNumber"/>
                        </li>
                        <li>
                            <label>使用人：</label>
                            <input type="text" name="userName"/>
                        </li>
                        <li>
                            <label>使用部门：</label>
                            <input type="text" name="department"/>
                        </li>
                        <li>
                            <label>资产归属：</label>
                            <input type="text" name="assetOwner"/>
                        </li>
                        <li>
                            <label>购置价值：</label>
                            <input type="text" name="purchaseValue"/>
                        </li>
                        <li>
                            <label>资产类型：</label>
                            <select name="assetType" th:with="type=${@dict.getType('asset_type')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>资产品牌：</label>
                            <select name="assetBrand" th:with="type=${@dict.getType('asset_brand')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>资产状态：</label>
                            <select name="assetStatus" th:with="type=${@dict.getType('asset_status')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>分类：</label>
                            <select name="assetCategory" th:with="type=${@dict.getType('asset_category')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li>
                            <label>属性：</label>
                            <select name="assetAttribute" th:with="type=${@dict.getType('asset_attribut')}">
                                <option value="">所有</option>
                                <option th:each="dict : ${type}" th:text="${dict.dictLabel}"
                                        th:value="${dict.dictValue}"></option>
                            </select>
                        </li>
                        <li class="select-time">
                            <label>购置日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginPurchaseDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" id="endTime" placeholder="结束时间"
                                   name="params[endPurchaseDate]"/>
                        </li>
                        <li class="select-time">
                            <label>质保日期：</label>
                            <input type="text" class="time-input" id="startTime" placeholder="开始时间"
                                   name="params[beginWarrantyDate]"/>
                            <span>-</span>
                            <input type="text" class="time-input" placeholder="结束时间"
                                   name="params[endWarrantyDate]"/>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="btn-group-sm" id="toolbar" role="group">
            <a class="btn btn-success" onclick="$.operate.add()" shiro:hasPermission="asset:assets:add">
                <i class="fa fa-plus"></i> 添加
            </a>
            <a class="btn btn-primary single disabled" onclick="$.operate.edit()"
               shiro:hasPermission="asset:assets:edit">
                <i class="fa fa-edit"></i> 修改
            </a>
            <a class="btn btn-danger multiple disabled" onclick="$.operate.removeAll()"
               shiro:hasPermission="asset:assets:remove">
                <i class="fa fa-remove"></i> 删除
            </a>
            <a class="btn btn-warning" onclick="$.table.exportExcel()" shiro:hasPermission="asset:assets:export">
                <i class="fa fa-download"></i> 导出
            </a>
            <a class="btn btn-warning" onclick="prints()" shiro:hasPermission="asset:assets:printmes">
                <i class="fa fa-download"></i> 打印
            </a>
        </div>
        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="include :: footer"/>
<script th:src="@{/js/pdfobject.min.js}"></script>
<script th:inline="javascript">
    var editFlag = [[${@permission.hasPermi('asset:assets:edit')}]];
    var removeFlag = [[${@permission.hasPermi('asset:assets:remove')}]];
    var printFlag = [[${@permission.hasPermi('asset:assets:print')}]];
    var assetTypeDatas = [[${@dict.getType('asset_type')}]];
    var assetBrandDatas = [[${@dict.getType('asset_brand')}]];
    var assetStatusDatas = [[${@dict.getType('asset_status')}]];
    var assetCategoryDatas = [[${@dict.getType('asset_category')}]];
    var assetAttributeDatas = [[${@dict.getType('asset_attribut')}]];
    var assetSupplier=[[${@dict.getType('asset_supplier')}]];
    var prefix = ctx + "asset/assets";

    $(function () {
        var options = {
            url: prefix + "/list",
            createUrl: prefix + "/add",
            updateUrl: prefix + "/edit/{id}",
            removeUrl: prefix + "/remove",
            exportUrl: prefix + "/export",
            modalName: "固定资产信息",
            columns: [{
                checkbox: true
            },
                {
                    field: 'assetNumber',
                    title: '资产编号'
                },
                {
                    field: 'assetName',
                    title: '资产名称'
                },
                {
                    field: 'assetType',
                    title: '资产类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetTypeDatas, value);
                    }
                },
                {
                    field: 'assetBrand',
                    title: '资产品牌',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetBrandDatas, value);
                    }
                },
                {
                    field: 'assetModel',
                    title: '资产型号'
                },
                {
                    field: 'supplier',
                    title: '供应商',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetSupplier, value);
                    },
                    visible: false
                },
                {
                    field: 'purchaseDate',
                    title: '资产购置日期',
                    visible: false
                },
                {
                    field: 'purchaseValue',
                    title: '资产购置价值',
                    visible: false
                },
                {
                    field: 'warrantyDate',
                    title: '质保日期',
                    visible: false
                },
                {
                    field: 'location',
                    title: '资产位置',
                    visible: false
                },
                {
                    field: 'ipAddress',
                    title: 'IP地址',
                    visible: false
                },
                {
                    field: 'snNumber',
                    title: 'SN号',
                    visible: false
                },
                {
                    field: 'macAddress',
                    title: 'MAC地址',
                    visible: false
                },
                {
                    field: 'oaNumber',
                    title: 'OA编号',
                    visible: false
                },
                {
                    field: 'userName',
                    title: '使用人'
                },
                {
                    field: 'userId',
                    title: '工号'
                },
                {
                    field: 'department',
                    title: '使用部门'
                },
                {
                    field: 'assetOwner',
                    title: '资产归属',
                    visible: false
                },
                {
                    field: 'assetStatus',
                    title: '资产状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetStatusDatas, value);
                    }
                },
                {
                    field: 'assetCategory',
                    title: '分类',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetCategoryDatas, value);
                    }
                },
                {
                    field: 'assetAttribute',
                    title: '属性',
                    visible: false,
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(assetAttributeDatas, value);
                    }
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var actions = [];
                        actions.push('<a class="btn btn-success btn-xs ' + editFlag + '" href="javascript:void(0)" onclick="$.operate.edit(\'' + row.assetNumber + '\')"><i class="fa fa-edit"></i>编辑</a> ');
                        actions.push('<a class="btn btn-danger btn-xs ' + removeFlag + '" href="javascript:void(0)" onclick="$.operate.remove(\'' + row.assetNumber + '\')"><i class="fa fa-remove"></i>删除</a>');
                        actions.push('<a class="btn btn-default btn-xs ' + printFlag + '" href="javascript:void(0)" onclick="printById(\'' + row.assetNumber + '\')"><i class="fa fa-align-right"></i>打印</a>');
                        return actions.join('');
                    }
                }]
        };
        $.table.init(options);
    });


    /* function printById(id) {
         $.ajax({
             url: "/asset/assets/printById", // 替换/backend-url为你的后端接口URL
             type: "POST",
             data: {id: id},
             responseType:'blob',// 替换为你要发送的数据字段名和对应的值
             success: function (response) {
                 console.log(response);
                 // 创建一个 Blob 对象并设置类型为 application/pdf
                 var blob = new Blob([response], {type: 'application/pdf'});

                 // 使用 URL.createObjectURL 方法创建 URL 并在浏览器中打开 PDF 文件
                 var url = URL.createObjectURL(blob);
                 window.open(url);

                 // 或者，您可以使用以下代码将 PDF 文件下载到本地计算机
                 // var a = document.createElement('a');
                 // a.href = url;
                 // a.download = 'document.pdf';
                 // a.click();
             },
             error: function (xhr, textStatus, errorThrown) {
                 console.error("请求失败：" + xhr.status);
                 console.error("异常信息：" + xhr.responseText); // 异常信息在响应的responseText中
             }
         });
     }*/

    function printById(id) {
        $.modal.confirm("确认要打印选中的数据吗?", function () {

            $.get({
                url: "/asset/assets/printById?id=" + id,
                xhrFields: {
                    responseType: 'blob'
                },
                success: function (response) {
                    console.log(response);
                    if (response.code == 500) {
                        $.modal.alertError(response.message);
                    }
                    var blob = new Blob([response], {type: 'application/pdf'});
                    var url = URL.createObjectURL(blob);
                    // 打印 PDF 文件
                    var win = window.open(url);
                    win.print(); // 自动触发打印
                },
                error: function (response) {
                    console.log(response)

                }
            });


        });
    }


    function prints() {
        table.set();
        var rows = $.common.isEmpty(table.options.uniqueId) ? $.table.selectFirstColumns() : $.table.selectColumns(table.options.uniqueId);
        $.modal.confirm("确认要打印选中的" + rows.length + "条数据吗?", function () {
            var ids=rows.join();

            $.get({
                url: "/asset/assets/prints?ids=" + ids,
                xhrFields: {
                    responseType: 'blob'
                },
                success: function (response) {
                    console.log(response);
                    if (response.code == 500) {
                        $.modal.alertError(response.message);
                    }
                    var blob = new Blob([response], {type: 'application/pdf'});
                    var url = URL.createObjectURL(blob);
                    // 打印 PDF 文件
                    var win = window.open(url);
                    win.print(); // 自动触发打印
                },
                error: function (xhr, textStatus, errorThrown) {
                    console.error("请求失败：" + xhr.status);
                    console.error("异常信息：" + xhr.responseText);
                }
            });
        });
    }


</script>
</body>
</html>